import EXIF from './exif';

export default (file, callback) => new Promise(res => {
    let exifdata = {
        isRotate: false, // 是否需要旋转图片
    };

    const realCallback = () => {
        res(exifdata);
        callback && callback(exifdata);
    };

    try {
        EXIF.getData(file, () => {
            exifdata = {
                ...exifdata,
                ...file.exifdata,
            };
            // Orientation 为6,8的时候需要旋转图片
            exifdata.isRotate = [6, 8].includes(Number(exifdata.Orientation));
            realCallback();
        });
    } catch (e) {
        realCallback();
    }
});
